import requests


class Upload:
    def __init__(self):
        """
        基础配置
        """
        # 请求头
        self.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'
        }
        # 上传链接
        self.upload_url = 'https://api.test.cn/upload'  # POST方法

    def upload(self):
        """
        上传文件
        """
        data = {
            'bucketName': 'test',
            'objectName': '测试附件.xlsx',
            'fileDownloadName': '测试附件.xlsx',
        }
        files = {
            'file': open('测试文件.xls', 'rb')
        }
        res = requests.post(url=self.upload_url, headers=self.headers, data=data, files=files)
        print(res.json())


if __name__ == '__main__':
    upload = Upload()
    upload.upload()
